import { Component } from 'react'
import { View } from '@tarojs/components'
import './index.scss'
import Taro from '@tarojs/taro'
import dayjs from "dayjs"
//公共组件
// import LgCheckbox from '../../../components/checkbox'
import PrCheckbox from './components/checkbox'

interface IndexProps{
  /**图标 1/楼牌 2/班牌 3/广播终端 */
  iconType?:1|2|3 
  /**item类型 【1】展示图标 【2】展示选择框(icon不生效) */
  itemType?:1|2
  /**checkBox状态，0不选，1选中，2半选 */
  value?:0|1|2
  /**索引，用于点击返回 */
  index:number
  /**点击卡片 */
  onClickItem?():void
  /**点击checkbox，只在itemType=2生效 */
  onCheckbox?(value:0|1,index:number):void
  /**是否有子项 */
  haveSub:boolean
}

interface IndexState{

}

export default class PrChooseDevicesItem extends Component <IndexProps,IndexState>{
  constructor(props) {
    super(props)
    this.state={

    }
    this.onClickItem = this.onClickItem.bind(this)
    this.onCheckbox = this.onCheckbox.bind(this)
  }

  UNSAFE_componentWillMount() { }

  componentDidMount() { }

  componentWillUnmount() { }

  onCheckbox(e,value,index){
    e.stopPropagation()//禁止冒泡
    this.props.onCheckbox?this.props.onCheckbox(value,index):""
  }
  onClickItem(){
    this.props.onClickItem?this.props.onClickItem():""
  }
  render() {
    let iconType = this.props.iconType || 1
    let itemType = this.props.itemType || 2
    let name = this.props.children || ""
    let haveSub = this.props.haveSub
    return (
      <View className='PrChooseDevicesItem fileMove_list_item'>
        <View className='fileMove_list_item_warp' onClick={this.onClickItem}>
          {
            itemType == 1?
            <View className='list_item_left'>
              <View className={`item_left_icon ${iconType==1?"icon_buildingBoard":iconType==2?"icon_classBoard":"icon_radioBroadcasts"}`}></View>
              <View className='item_left_text'>{name}</View>
            </View>
            :
            <PrCheckbox 
              disabled={false} 
              type="B" 
              index={this.props.index} 
              onClick={this.onCheckbox} 
              value={this.props.value || 0}
            >  
              {name}
            </PrCheckbox>
          }
          {
            haveSub?
            <View className='icon-b01901'></View>
            :""
          }
          {/* <View className='icon-b01901'></View> */}
        </View>
      </View>
    )
  }
}
